function powerflow = lijnfout_14_index_Q(start,eind)
%dips bepalen ten gevolge van een tijdelijke lijnfout
%clear all
%einde_interval = size(Line.con,1);   %# lijnen bekijken
teller = 0;
alle_spanningen = zeros(200*(eind+1-start),15);
alle_q = zeros(200*(eind+1-start),15);
einde_interval = (eind+1-start);
tijd = zeros(200,(eind+1-start));
%global PV;
ok = 0;
%teller1 = 1;
for k=start:eind;
    
    while ok ==0
    
    filename = sprintf('bus%03d',k);
    initpsat;
    Settings.plottype = 2;
    Settings.freq = 60;
    Settings.absvalues= 'on';
    runpsat(filename,'pf');
    %Settings.fixt = 1;
    %Settings.tstep = 1;%0.05; %TRAAAAAAAAAAAAAG
    Settings.plottype = 2;
    Settings.freq = 60;
    Settings.tf = 20;
%     Settings.method = 1;
%     Settings.deltat = 0.1;
    Settings.absvalues= 'on';
    
    
    filename = sprintf('bus%03d.m',k);
    
    idx_begin = DAE.n+Bus.n+1;
    idx_eind = DAE.n+2*Bus.n;
    idx_begin_q = DAE.n+DAE.m+Bus.n+1;
    idx_eind_q = DAE.n+DAE.m+2*Bus.n;
    
        fid=fopen(filename,'a');
        
        Varname.idx(:,1) = 0;
        teller1 = 1;
        for i = idx_begin:idx_eind
            Varname.idx(teller1,1) = i;
            teller1 = teller1+1;
        end
        for i = idx_begin_q:idx_eind_q
            Varname.idx(teller1,1) = i;
            teller1 = teller1+1;
        end
        count = fprintf(fid, 'Varname.idx = [... \n');
        format = [repmat('%8.4g; ',1,7),'\n'];
        count = fprintf(fid,format,Varname.idx');
%         count = fprintf(fid,'\n');
        count = fprintf(fid,'   ];\n\n');
        fclose(fid);
    
    runpsat('td');
    %begint vanaf index 0... (STOM!!!)
   v = genvarname('voltages_fout_lijn', who);
   eval([v ' = Varout.vars']);%(:,(size(Bus.con,1)+1):2*size(Bus.con,1))']);
   lengte = size(Varout.vars,1)
   
   %spanning per tijdsstap per bus
   alle_spanningen(1+200*teller:200*teller+lengte,:) = Varout.vars(:,1:Bus.n);
   
   alle_q(1+200*teller:200*teller+lengte,:) = Varout.vars(:,Bus.n+1:2*Bus.n);
   
   t = genvarname('tijd_fout_lijn', who);
   eval([t ' = Varout.t']);%(:,(size(Bus.con,1)+1):2*size(Bus.con,1))']);
   
   %tijd per stap per lijn
   tijd(1:lengte,k) = Varout.t;
   
   ok = 1;
   test = 0;
   %k nog laten varieren over de bussen!!!!!   (1-14)
   for l = 1:1:14
   if test == 0
   if sum(alle_spanningen(20+200*teller:140+200*teller,l))<=70
       
       ok = 0;
       
%        IEEE_14_bus_original;
        filename = sprintf('bus%03d.m',k);
%         eval(filename);
%         filename = [filename,'.m'];
        fid=fopen(filename,'a');
       %impedantie aanpassen om netwerk toch te laten oplossen
       Impedantie = Fault.con(1,7)*4;
       Fault.con(1,7) = Impedantie;
       Fault.con(1,8) = Impedantie;
       
       %print Fault.con
        count = fprintf(fid, 'Fault.con = [... \n');
        count = fprintf(fid,'%4d %4.4g %4.4g %3.4g %2.4g %4.5g %6.5g %6.5g\n',Fault.con);
%         count = fprintf(fid,'\n');
        count = fprintf(fid,'   ];\n\n');
       
        fclose(fid);
        test = 1;
   end
   end
   end
    %teller1 = teller1+1;
   end
   ok = 0;
   closepsat;
   teller = teller+1;
   
%    %save dips tijd alle_spanningen;
%    save lijnfout tijd alle_spanningen einde_interval;
end

 %save dips tijd alle_spanningen;
   save lijnfout tijd alle_spanningen alle_q einde_interval;
% initpsat;
% Settings.plottype = 2;
% Settings.freq = 60;
% Settings.absvalues= 'on';
% runpsat('IEEE_14_bus_original','pf');
% Settings.fixt = 1;
% Settings.tstep = 1;%0.05;
% Settings.freq = 60;
%     Settings.absvalues= 'on';
% runpsat('td');
% normaal = Varout.vars;
